﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PoiBrowser
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
            frmBrowser f = new frmBrowser();
            f.MdiParent = this;
            f.Show();
        }



        #region Tool Strip Menu 

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void iGOToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ofd1.CheckFileExists = true;
            ofd1.Filter = "IGO POI|*.txt";
            DialogResult res = ofd1.ShowDialog();
            if (res == System.Windows.Forms.DialogResult.OK)
            {
                Engine.PoiReader reader = new Engine.PoiReader();
                Engine.POI.BasePoi []arr = (Engine.POI.BasePoi[]) reader.Load(ofd1.FileName);
                Form openF = findOpenForm(typeof(frmBrowser));
                if (openF != null)
                    openF.BringToFront();
                else
                {
                    frmBrowser f = new frmBrowser();
                    f.MdiParent = this;
                    f.Show();
                }
            }
        }

        #endregion




        #region Private Static Functions

        /// <summary>
        /// Searches for open forms
        /// </summary>
        /// <param name="formType"></param>
        /// <returns></returns>
        private Form findOpenForm(Type formType)
        {
            foreach (Form f in Application.OpenForms)
            {
                if (f.GetType() == formType)
                    return f;
            }
            return null;
        }

        #endregion
    }
}
